import time
from keras.layers import Conv2D, Activation, MaxPooling2D
from dao.evaluationdao import EvaluationDao
import keras.layers

# try:
#     a = []
#     print(a[1])
#
# except IndexError as e:
#     raise e

# s=time.time()
# a=Conv2D
# b=Conv2D
# print(a==b)
# print(Conv2D.__name__)
# e=time.time()
# print(e-s)

def hhh():
    print("hhh")
clazz = globals()['Conv2D']
a = Conv2D
print(clazz)
print(a == clazz)

print((1, 2, 3, "111").index("111"))

def plot_roc(self, y, y_pre):
    # micro：多分类　　
    # weighted：不均衡数量的类来说，计算⼆分类metrics的平均
    # macro：计算⼆分类metrics的均值，为每个类给出相同权重的分值。
    # roc_curve:真正率（True Positive Rate , TPR）或灵敏度（sensitivity）
    # 横坐标：假正率（False Positive Rate , FPR）
    # Compute ROC curve and ROC area for each class
    fpr = dict()
    tpr = dict()
    roc_auc = dict()
    for i in range(Config.NUM_CLASSES):
        fpr[i], tpr[i], _ = roc_curve(y[:, i], y_pre[:, i])
    roc_auc[i] = auc(fpr[i], tpr[i])
    # Compute micro-average ROC curve and ROC area
    fpr["micro"], tpr["micro"], _ = roc_curve(y.ravel(), y_pre.ravel())
    roc_auc["micro"] = auc(fpr["micro"], tpr["micro"])
    # Compute macro-average ROC curve and ROC area
    # First aggregate all false positive rates
    all_fpr = np.unique(np.concatenate([fpr[i] for i in range(Config.NUM_CLASSES)]))
    # Then interpolate all ROC curves at this points
    mean_tpr = np.zeros_like(all_fpr)
    for i in range(Config.NUM_CLASSES):
        mean_tpr += interp(all_fpr, fpr[i], tpr[i])
    # Finally average it and compute AUC
    mean_tpr /= Config.NUM_CLASSES
    fpr["macro"] = all_fpr
    tpr["macro"] = mean_tpr
    roc_auc["macro"] = auc(fpr["macro"], tpr["macro"])
    # Plot all ROC curves
    lw = 2
    plt.figure()
    plt.plot(fpr["micro"], tpr["micro"],
             label='micro-average ROC curve (area = {0:0.2f})'
                   ''.format(roc_auc["micro"]),
             color='deeppink', linestyle=':', linewidth=4)
    plt.plot(fpr["macro"], tpr["macro"],
             label='macro-average ROC curve (area = {0:0.2f})'
                   ''.format(roc_auc["macro"]),
             color='navy', linestyle=':', linewidth=4)
    # colors = cycle(['aqua', 'darkorange', 'cornflowerblue'])
    # for i, color in zip(range(Config.NUM_CLASSES), colors):
    #     plt.plot(fpr[i], tpr[i], color=color, lw=lw,
    #
    #              # label='ROC curve of class {0} (area = {1:0.2f})'.format(i, roc_auc[i]))
    #              # label='ROC curve of class '+str(i)+' (area = '+str(roc_auc[i])+')')
    #              )
    plt.plot([0, 1], [0, 1], 'k--', lw=lw)
    # plt.xlim([0.0, 1.0])
    # plt.ylim([0.0, 1.05])
    # plt.xlabel('False Positive Rate')
    # plt.ylabel('True Positive Rate')
    # plt.title('Some extension of Receiver operating characteristic to multi-class')
    # plt.legend(loc="lower right")
    plt.show()